package routinecontroller

import (
	"agent-list---web-development/list/common"
	"agent-list---web-development/list/model"
	"agent-list---web-development/list/response"
	"net/http"

	"github.com/gin-gonic/gin"
)

// 获取打卡内容(打卡记录数组)
func RoutineInfo(c *gin.Context) {
	// 获取信息
	DB := common.GetDB()
	account := c.Query("account")
	title := c.Query("title")
	//获取对应的用户记录
	var routine model.Routine
	DB.Where("useraccount=? and title=?", account, title).First(&routine)

	if routine.Id == 0 {
		response.Response(c, http.StatusUnprocessableEntity, 410, nil, "打卡事项不存在")
		return
	}
	//数据验证
	// 返回查找结果
	response.Success(c, gin.H{"reconding": routine.Reconding}, "获取事项成功")
}

// 获取打卡创建时间
func GetRoutinetime(c *gin.Context) {
	// 获取信息
	DB := common.GetDB()
	account := c.Query("account")
	title := c.Query("title")

	//获取对应的用户记录
	var routine model.Routine
	DB.Where("useraccount=? and title=?", account, title).First(&routine)

	if routine.Id == 0 {
		response.Response(c, http.StatusUnprocessableEntity, 410, nil, "打卡事项不存在")
		return
	}
	//数据验证
	// 返回查找结果
	time := routine.STime.Format("2006-01-02")
	response.Success(c, gin.H{"stime": time}, "获取事项成功")
}
